<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="推荐人电话">
              <el-input v-model="form.username" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="被推荐人电话">
              <el-input v-model="form.triggerUsername" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="奖励状态">
              <el-select v-model="form.status" placeholder="请选择">
                <el-option v-for="item in statusList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
              <!-- <el-button type="primary">导出</el-button> -->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <!-- table列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column fixed prop="realname" label="推荐人姓名" />
        <el-table-column prop="username" label="推荐人电话" >
 <template slot-scope="scope">
            <div>{{scope.row.username | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="signtimeStr" label="推荐人加盟时间" />
        <el-table-column prop="triggerRealname" label="被推荐人姓名" />
        <el-table-column prop="triggerUsername" label="被推荐人电话" >
          <template slot-scope="scope">
            <div>{{scope.row.triggerUsername | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="triggerSigntimeStr" label="被推荐人加盟时间" />
        <el-table-column prop="triggerCompanyName" label="被推荐人加盟公司" />
        <el-table-column label="奖励状态">
          <template slot-scope="scope">
            <div v-if="scope.row.status==0 || scope.row.status==2">{{ scope.row.statusname }}</div>
            <div v-else>
              <p>已发放账户</p>
              <p>到账时间：{{ scope.row.updatedAtStr }}</p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="listForm.pageNum"
            :page-sizes="page_sizes"
            :page-size="listForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { pullNewFOIndexList } from '@/api/financialOther'
export default {
  name: 'PullNewFOIndex',
  filters: {},
  data() {
    return {
      tableLoading: true,
      dates: [],
      form: {
        username: '',
        triggerUsername: '',
        status: null,
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 60,
      listForm: {
        pageNum: 1,
        pageSize: 10
      },
      statusList: [
        { id: null, name: '全部' },
        { id: 0, name: '未奖励' },
        { id: 1, name: '已奖励' },
        { id: 2, name: '已过期' }
      ]
    }
  },
  mounted() {
    this.getList(this.listForm)
  },
  methods: {
    // 成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + '成功',
        type: 'success'
      })
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + '失败')
    },
    // 列表数据获取
    getList(e) {
      this.tableLoading = true
      const datas = e
      pullNewFOIndexList(datas)
        .then(res => {
          if (!res.data.code) {
            this.tableData = res.data.data.list
            this.page_totals = res.data.data.count
            if (this.tableData.length > 0) {
              this.tableData.forEach(item => {
                this.statusList.forEach(list => {
                  if (item.status == list.id) {
                    item.statusname = list.name
                  }
                })
              })
            }
          } else {
            this.$message.error(res.data.msg)
          }
          this.tableLoading = false
        })
        .catch(error => {
          this.$message.error(error)
        })
    },
    // 查询
    searchFn() {
      this.form.pageNum = 1
      this.getList(this.form)
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val
      this.getList(this.form)
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val
      this.getList(this.form)
    }
  }
}
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
